package com.suxin.test.netty.adv.vo;

import lombok.Data;

import java.io.Serializable;
import java.util.UUID;

/**
 * @Author: tang
 * @Description:
 * @Date 2025/1/21 10:52
 */
@Data
public class Message implements Serializable {

    private MessageHeader messageHeader;

    private Object body;

    public Message() {
    }

    public static Message buildClientHeartBeat() {
        MessageHeader messageHeader = new MessageHeader();
        messageHeader.setType(MessageType.HEARTBEAT_REQ.value());
        messageHeader.setMsgId(UUID.randomUUID().toString());
        messageHeader.setMd5(EncryptUtils.encryptObj("ping~~"));
        Message message = new Message();
        message.setMessageHeader(messageHeader);
        message.setBody("ping~~");
        return message;
    }

    public static Message buildServerHeartBeat() {
        MessageHeader messageHeader = new MessageHeader();
        messageHeader.setType(MessageType.HEARTBEAT_RESP.value());
        messageHeader.setMsgId(UUID.randomUUID().toString());
        messageHeader.setMd5(EncryptUtils.encryptObj("pong~~"));
        Message message = new Message();
        message.setMessageHeader(messageHeader);
        message.setBody("pong~~");
        return message;
    }


    public static Message buildSendServerMsg(String msg) {
        MessageHeader messageHeader = new MessageHeader();
        messageHeader.setType(MessageType.ONE_WAY.value());
        messageHeader.setMsgId(UUID.randomUUID().toString());
        messageHeader.setMd5(EncryptUtils.encryptObj(msg));
        Message message = new Message();
        message.setMessageHeader(messageHeader);
        message.setBody(msg);
        return message;
    }

    public static Message buildSendTwoServerMsg(String msg,String msgId) {
        MessageHeader messageHeader = new MessageHeader();
        messageHeader.setType(MessageType.SERVICE_RESP.value());
        messageHeader.setMsgId(msgId);
        messageHeader.setMd5(EncryptUtils.encryptObj(msg));
        Message message = new Message();
        message.setMessageHeader(messageHeader);
        message.setBody(msg);
        return message;
    }


}
